/*
 *  Copyright 2011 Alexey Andreev.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.xthl.wiki;

import java.io.File;
import java.io.IOException;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.ru.RussianAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.NIOFSDirectory;
import org.apache.lucene.util.Version;

/**
 *
 * @author Alexey Andreev
 */
class LuceneProviderImpl implements LuceneProvider { 
    private Directory directory;
    private IndexWriter writer;
    private Analyzer analyzer = new RussianAnalyzer(Version.LUCENE_30);
    private IndexSearcher searcher;

    public LuceneProviderImpl() {
        try {
            directory = new NIOFSDirectory(new File("lucene/index.bin"));
            writer = new IndexWriter(directory, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);
            searcher = new IndexSearcher(directory);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    @Override
    public IndexWriter getWriter() {
        return writer;
    }
    
    @Override
    public IndexSearcher getSearcher() {
        return searcher;
    }

    @Override
    public Analyzer getAnalyzer() {
        return analyzer;
    }
}
